<?php

/**
 * Description of StylesheetView
 *
 * @author Ian Clarence <ian.clarence@gmail.com>
 */
final class StylesheetView extends ViewStylesheet {
    
    /**
     * The constructor.
     */
    public function __construct($fields = array()) {
        parent::__construct($fields);
        $this->applyCssRules();
    }
    
    /**
     * Adding additional CSS rules. 
     */
    private function applyCssRules() {        
    
        /**
        * A few universal CSS rules: centre align the page with a given background colour, and given width.
        * Any element of class 'hidden' will be made invisible. 
        */
        $this->addCssRules(MainCss::make($this->fields));
        
        switch (DEBUGGING_MODE) {
            case OFF:
                
                /**
                * Header.
                */
                $this->addCssRules(HeaderCss::make($this->fields));
                
                /**
                 * Primary navigation. 
                 */
                $this->addCssRules(PrimaryNavigationCss::make($this->fields));
                
                /**
                * Homepage.
                */
                if ($this->fields['page']['name'] == 'home') {                    
                    $this->addCssRules(HomepageCss::make($this->fields));
                }
                
                /**
                 * Internal page. 
                 */
                else {
                    
                    /**
                     * Subcontainer, contents and footer. 
                     */
                    $this->addCssRules(InternalPageCss::make($this->fields));
                    
                    /**
                    * Left navigation. 
                    */
                    $this->addCssRules(LeftNavigationCss::make($this->fields));
                    
                }
                
                /**
                 * Footer. 
                 */
                $this->addCssRules(FooterCss::make($this->fields));
                
                /**
                 * Template variables: can only be seen in development mode. 
                 */
                if (SERVER == DEVELOPMENT_SERVER && SHOW_TEMPLATE_VARIABLES == YES) {
                    $this->addCssRules(TemplateVariablesCss::make($this->fields));
                }                
                
                /**
                 * Form styling.
                 */
                $this->addCssRules(HtmlFormCss::make($this->fields));
                
                break;
				
            case ON:
                
                /**
                 * Debugging mode on. 
                 */
                $this->addCssRules(DebuggingCss::make($this->fields));
                break;
        }
    }

    /**
     * Viewing the stylesheet: returning the CSS.
     *
     * @return string
     */
    public function view() {
        return parent::view();
    }

}